/*
 * TTitleBar.h
 *
 *  Created on: 2011-5-12
 *      Author: Jeff
 */

#ifndef TTitleBar_H_
#define TTitleBar_H_

#include "TElidedLabel.h"

#include <QSpacerItem>
#include <QPushButton>

class TTitleBar
  : public QFrame
{
	Q_OBJECT

public:
  explicit TTitleBar(const QString& name, QWidget *parent);
    explicit TTitleBar(QWidget *parent);

signals:
  void mouseButtonDblClicked();
  void beginToMove(const QPoint&);
  void moveRequested(const QPoint&, const QPoint&);
  void moveFinished(const QPoint&);

public:
  const QString& getText() const;
  void setText(const QString& text);
  void setTextVisible(bool setting);

  void addWidget(QWidget* w, Qt::Alignment alignment = Qt::AlignLeft | Qt::AlignVCenter,
      bool at_end = true);
  void removeWidget(QWidget* w);

  void addSpacerItem(QSpacerItem* item, bool at_end = true);
  void removeSpacerItem(QSpacerItem* item);

protected:
  void mousePressEvent(QMouseEvent* e);
  void mouseMoveEvent(QMouseEvent* e);
  void mouseReleaseEvent(QMouseEvent* e);

  bool event(QEvent* e);

private:
  TElidedLabel*	_textLabel;
  bool _pressed;
  QPoint _pressPosition;
  QPoint _moveStartPosition;
};
#endif /* TTitleBar_H_ */
